package com.chijun.mform.create.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chijun.mform.R;
import com.chijun.mform.create.adapter.SelectOptionReFieldAdapter;
import com.chijun.mform.create.mode.FormField;
import com.chijun.mform.create.mode.FormFieldOption;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.b.c.recycler.BaseRecycler;

import java.util.List;

/**
 * 显示选项可关联以及已关联的字段dialog
 * 点击后返回
 */
public class OptionReFieldDialog extends DialogBase {

    List<FormField> formFieldList;//全部字段
    List<FormField> formOptionReFieldList; //当前选项关联的字段
    ISelectOptionReFormField iSelectOptionReFormField;
    FormFieldOption option;

    /**
     *
     * @param context 上下文
     * @param formFieldList  全部字段
     * @param formOptionReFieldList 当前选项关联的字段
     */
    public OptionReFieldDialog(@NonNull Context context, FormFieldOption option, List<FormField> formFieldList, List<FormField> formOptionReFieldList, @NonNull ISelectOptionReFormField iSelectOptionReFormField) {
        super(context);
        this.option = option;
        this.formFieldList = formFieldList;
        this.formOptionReFieldList = formOptionReFieldList;
        this.iSelectOptionReFormField = iSelectOptionReFormField;
    }

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_field_option_re);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.5);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();


        setTitleCenterText(option.content);
        setTitleRightText("OK").setOnClickListener(V->dismiss());

        BaseRecycler<FormField> fieldBaseRecycler = findViewById(R.id.dialog_field_option_re_rec);
        fieldBaseRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
        fieldBaseRecycler.setAdapter(new SelectOptionReFieldAdapter(formFieldList, formOptionReFieldList, iSelectOptionReFormField));
    }

}
